home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_539 / simplerexx / simplerexxexample.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  218 lines

  1. /*
  2.  * This is an example of how to use the SimpleRexx code.
  3.  */
  4.  
  5. #include    <exec/types.h>
  6. #include    <libraries/dos.h>
  7. #include    <libraries/dosextens.h>
  8. #include    <intuition/intuition.h>
  9.  
  10. #include    <proto/exec.h>
  11. #include    <proto/intuition.h>
  12.  
  13. #include    <rexx/storage.h>
  14. #include    <rexx/rxslib.h>
  15.  
  16. #include    <stdio.h>
  17. #include    <string.h>
  18.  
  19. #include    "SimpleRexx.h"
  20.  
  21. /*
  22.  * Lattice control-c stop...
  23.  */
  24. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  25. int chkabort(void) { return(0); }  /* really */
  26.  
  27. /*
  28.  * The strings in this program
  29.  */
  30. char *strings[]=
  31. {
  32.     "50: Window already open",        /* STR_ID_WINDOW_OPEN */
  33.     "101: Window did not open",        /* STR_ID_WINDOW_ERROR */
  34.     "50: No Window",            /* STR_ID_WINDOW_NONE */
  35.     "80: Argument error to WINDOW command",    /* STR_ID_WINDOW_ARG */
  36.     "100: Unknown command",            /* STR_ID_COMMAND_ERROR */
  37.     "ARexx port name: %s\n",        /* STR_ID_PORT_NAME */
  38.     "No ARexx on this system.\n",        /* STR_ID_NO_AREXX */
  39.     "SimpleRexxExample Window"        /* STR_ID_WINDOW_TITLE */
  40. };
  41.  
  42. #define    STR_ID_WINDOW_OPEN    0
  43. #define    STR_ID_WINDOW_ERROR    1
  44. #define    STR_ID_WINDOW_NONE    2
  45. #define    STR_ID_WINDOW_ARG    3
  46. #define    STR_ID_COMMAND_ERROR    4
  47. #define    STR_ID_PORT_NAME    5
  48. #define    STR_ID_NO_AREXX        6
  49. #define    STR_ID_WINDOW_TITLE    7
  50.  
  51. /*
  52.  * NewWindow structure...
  53.  */
  54. static struct NewWindow nw=
  55. {
  56.     97,47,299,44,-1,-1,
  57.     CLOSEWINDOW,
  58.     WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH,
  59.     NULL,NULL,
  60.     NULL,
  61.     NULL,NULL,290,40,-1,-1,WBENCHSCREEN
  62. };
  63.  
  64. /*
  65.  * A *VERY* simple and simple-minded example of using the SimpleRexx.c code.
  66.  *
  67.  * This program, when run, will print out the name of the ARexx port it
  68.  * opens.  Use that port to tell it to SHOW the window.  You can also
  69.  * use the ARexx port to HIDE the window, to READTITLE the window's
  70.  * titlebar, and QUIT the program.  You can also quit the program by
  71.  * pressing the close gadget in the window while the window is up.
  72.  *
  73.  * Note: You will want to RUN this program or have another shell available such
  74.  *       that you can still have access to ARexx...
  75.  */
  76. void main(int argc,char *argv[])
  77. {
  78. short    loopflag=TRUE;
  79. AREXXCONTEXT    RexxStuff;
  80. struct    Window    *win=NULL;
  81. ULONG    signals;
  82.  
  83.     if (IntuitionBase=(struct IntuitionBase *)
  84.                     OpenLibrary("intuition.library",NULL))
  85.     {
  86.         /*
  87.          * Note that SimpleRexx is set up such that you do not
  88.          * need to check for an error to initialize your REXX port
  89.          * This is so your application could run without REXX...
  90.          */
  91.         RexxStuff=InitARexx("Example","test");
  92.  
  93.         if (argc)
  94.         {
  95.             if (RexxStuff) printf(strings[STR_ID_PORT_NAME],
  96.                             ARexxName(RexxStuff));
  97.             else printf(strings[STR_ID_NO_AREXX]);
  98.         }
  99.  
  100.         while (loopflag)
  101.         {
  102.             signals=ARexxSignal(RexxStuff);
  103.             if (win) signals|=(1L << (win->UserPort->mp_SigBit));
  104.  
  105.             if (signals)
  106.             {
  107.             struct    RexxMsg        *rmsg;
  108.             struct    IntuiMessage    *msg;
  109.  
  110.                 signals=Wait(signals);
  111.  
  112.                 /*
  113.                  * Process the ARexx messages...
  114.                  */
  115.                 while (rmsg=GetARexxMsg(RexxStuff))
  116.                 {
  117.                 char    cBuf[24];
  118.                 char    *nextchar;
  119.                 char    *error=NULL;
  120.                 char    *result=NULL;
  121.                 long    errlevel=0;
  122.  
  123.                     nextchar=stptok(ARG0(rmsg),
  124.                                 cBuf,24," ,");
  125.                     if (*nextchar) nextchar++;
  126.  
  127.                     if (!stricmp("WINDOW",cBuf))
  128.                     {
  129.                         if (!stricmp("OPEN",nextchar))
  130.                         {
  131.                             if (win)
  132.                             {
  133.                                 error=strings[STR_ID_WINDOW_OPEN];
  134.                                 errlevel=5;
  135.                             }
  136.                             else
  137.                             {
  138.                                 nw.Title=strings[STR_ID_WINDOW_TITLE];
  139.                                 if (!(win=OpenWindow(&nw)))
  140.                                 {
  141.                                     error=strings[STR_ID_WINDOW_ERROR];
  142.                                     errlevel=30;
  143.                                 }
  144.                             }
  145.                         }
  146.                         else if (!stricmp("CLOSE",nextchar))
  147.                         {
  148.                             if (win)
  149.                             {
  150.                                 CloseWindow(win);
  151.                                 win=NULL;
  152.                             }
  153.                             else
  154.                             {
  155.                                 error=strings[STR_ID_WINDOW_NONE];
  156.                                 errlevel=5;
  157.                             }
  158.                         }
  159.                         else
  160.                         {
  161.                             error=strings[STR_ID_WINDOW_ARG];
  162.                             errlevel=20;
  163.                         }
  164.                     }
  165.                     else if (!stricmp("READTITLE",cBuf))
  166.                     {
  167.                         if (win)
  168.                         {
  169.                             result=win->Title;
  170.                         }
  171.                         else
  172.                         {
  173.                             error=strings[STR_ID_WINDOW_NONE];
  174.                             errlevel=5;
  175.                         }
  176.                     }
  177.                     else if (!stricmp("QUIT",cBuf))
  178.                     {
  179.                         loopflag=FALSE;
  180.                     }
  181.                     else
  182.                     {
  183.                         error=strings[STR_ID_COMMAND_ERROR];
  184.                         errlevel=20;
  185.                     }
  186.  
  187.                     if (error)
  188.                     {
  189.                         SetARexxLastError(RexxStuff,rmsg,error);
  190.                     }
  191.                     ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  192.                 }
  193.  
  194.                 /*
  195.                  * If we have a window, process those messages
  196.                  */
  197.                 if (win) while (msg=(struct IntuiMessage *)
  198.                             GetMsg(win->UserPort))
  199.                 {
  200.                     if (msg->Class==CLOSEWINDOW)
  201.                     {
  202.                         /*
  203.                          * Quit if the close gadget...
  204.                          */
  205.                         loopflag=FALSE;
  206.                     }
  207.                     ReplyMsg((struct Message *)msg);
  208.                 }
  209.             }
  210.             else loopflag=FALSE;
  211.         }
  212.         if (win) CloseWindow(win);
  213.  
  214.         FreeARexx(RexxStuff);
  215.         CloseLibrary((struct Library *)IntuitionBase);
  216.     }
  217. }
  218.